﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VCC.Site.ViewModels.BoxQuickSearchAdModel>" %>
<!--Start Middle Submenu-->
<form method="post" action="/Ad/index" id="QuickSearchAd">
<div id="MiddleSubMenu" style="padding-bottom:5px;">
    <div class="home-top-search">
        <div class="home-top-search-keyword" onclick="ForcusOnTextInput();" placeholder ="Nhập từ khóa để tìm theo cụm từ">
        <div id="list-subitem"></div>
            <input type="text" id="txtKeyword" placeholder ="Nhập khu vực (Suburb or PostCode) bạn muốn tìm" name="txtKeyword" class="txtKeyword">
            <%=Html.Hidden("ListSubID")%>
            <span id="loadingSubur" style="display:none;float: left; padding: 4px;"><img src="/Images/indicator.gif"/></span>
        </div>
        <div id="home-top-search" class="advance-select-box">
            <%=Html.DropDownList("dropCate" , new SelectList(Model.Categories, "Value", "Text",Model.CurrentCateID).ToList(), new { @class = "required dropdown-list", style="width:210px", title = "Chọn danh mục tin rao bạn muốn tìm!" })%>
        </div>
        <img title="Search" alt="Search" id="btnSearch" name="btnSearch" alt="Tìm kiếm" class="fg-button fg-button-bg-default fg-button-toggleable ui-corner-all" onclick="QuickSearchSubmit();" src="/Images/header-bottom-button.jpg">
        <div id="post-an-ad">
            <a href="/dang-tin" rel="nofollow" title="Đăng tin miễn phí | Post an Ad Free">
              <span style="float: left;text-transform: uppercase; background-color: rgb(255, 170, 33); font-weight: bold; border-radius: 3px; margin-top: 3px; line-height: 24px; padding-left: 0px; width: 160px; text-align: center; padding-bottom: 1px;">Đăng tin|Post an Ad</span>
            </a>
        </div>
    </div>
    
    <div style="clear: both;"></div>
</div>
</form>
<!--End middle submenu-->
<script type="text/javascript">
    function QuickSearchSubmit() {
        document.forms["QuickSearchAd"].submit();
//        var keword = $("#txtKeyword").val();
//        if (keword != null && keword != "") {
//            document.forms["QuickSearchAd"].submit();
//        }
//        else {
//            document.getElementById("txtKeyword").style.borderColor = "red";
//            $("#txtKeyword").focus();
//        }
    }
    function ForcusOnTextInput() {
        $("#txtKeyword").focus();
    }
    // Start Load du lieu Autocomplete for filed Select tag: Created by Vietlv//
    $("#txtKeyword").autocomplete({
        minLength: 2,
        source: function(request, response) {
            $("#loadingSubur").show();
            var dm = GetDomain();
            var ul = dm + "/AjaxData/SearchSuburb";
            $.ajax({
                url: ul,
                dataType: "json",
                data: {
                    keyword: extractLast(request.term)
                },
                success: function(data) {
                    $("#loadingSubur").hide();
                    response($.map(data, function(item) {
                        return {
                            label: item.FullName,
                            value: item.Keyword,
                            id: item.ID
                        }
                    }));
                }
            });
        },
        focus: function() {
            // prevent value inserted on focus
            return false;
        },
        select: function(event, ui) {
            var terms = split(this.value);
            // remove the current input
            terms.pop();
            // add the selected item
            //     terms.push(ui.item.value);
            // add placeholder to get the comma-and-space at the end
            terms.push("");
            this.value = terms.join("");
            //Them sub item
            var subitem = "<div id=\"sid" + ui.item.id + "\" class=\"sub-item\">" + ui.item.label + "<a class=\"remove\" title=\"Remove\" href=\"javascript:RemoveSubItem(" + ui.item.id + ")\">\×</a></div>";
            $("#list-subitem").append(subitem);
            $("#txtKeyword").attr("Style", "width:60px"); // resize text input
            $("#txtKeyword").attr("placeholder", "");//Remove placeholder
            //end sub item
            var termsk = split($('#ListSubID').val());
            // remove the current input
            termsk.pop();
            // add the selected item
            termsk.push(ui.item.id);
            // add placeholder to get the comma-and-space at the end
            termsk.push("");
            $('#ListSubID').val(termsk.join(","));
            return false;
        }
    });
    /*--Remove subur item */
    function RemoveSubItem(id) {
        $("#sid" + id).remove();
        var s = $("#ListSubID").val();
        var snew = s.replace(id + ",", "");
        $("#ListSubID").val(snew);
        if (snew == "" || snew == " ") {
            $("#txtKeyword").attr("Style", "width:290px");
            $("#txtKeyword").attr("placeholder","Nhập khu vực (Suburb or PostCode) bạn muốn tìm");
        }
    }
    /**/
</script>